# coding: utf8
"""
:author: Tony 2015/8/12
"""
__author__ = 'Tony'

from django.core.management.base import BaseCommand
from umeng_tool.analyse.proxy import urlopen_with_location
from umeng_tool.analyse.proxy.config import proxy_list


class Command(BaseCommand):
	def handle(self, *args, **options):
		able = []
		disable = []
		url = 'http://dayi.im/proxy/test/'
		for pid in proxy_list:
			print 'test pid[%s]' % pid
			try:
				if urlopen_with_location(url, location=pid, timeout=5) == 'success':
					able.append(proxy_list[pid])
				else:
					disable.append(proxy_list[pid])
			except Exception as ex:
				print ex
				disable.append(proxy_list[pid])

		print '\navailable proxy[%s]:' % len(able)
		for i in able:
			print 'ip: %s, port: %s, username: %s, passwd: %s' % i

		print '\nunavailable proxy[%s]:' % len(disable)
		for i in disable:
			print 'ip: %s, port: %s, username: %s, passwd: %s' % i

